export default {
  name: "basic",
  methods: {
    getKey(str) {
      let position = str.lastIndexOf("/");
      return str.substring(position + 1, str.length);
    },
    alterKey(str, key) {
      let position = str.lastIndexOf("/");
      return str.substring(0, position + 1) + key;
    },
    getLocation(str) {
      if (str.search("search") > 0) {
        return this.getUrl(str);
      } else if (str.search("operation") > 0) {
        return this.getUrl(str);
      } else {
        return str;
      }
    },
    capitalize(value) {
      if (!value) return "";
      value = value.toString();
      return value.charAt(0).toUpperCase() + value.slice(1);
    },
    getUrl(str) {
      let position = str.indexOf("/");
      return str.substring(0, position);
    },
    vaild(value) {
      return typeof value == "undefined" || value == "";
    },
    getSort(location, str) {
      if (str != null) {
        console.log("判断sortBy");
        if (location.search("search") == -1) {
          return str;
        } else {
          console.log("转字母");
          console.log(str);
          console.log(this.upperFirstLetter(str));
          return this.upperFirstLetter(str);
        }
      } else {
        return str;
      }
    },
    upperFirstLetter(str) {
      return str.replace(/([A-Z])/g, "_$1").toLowerCase();
    }
  }
};
